package org.cometmi.gwt.comet.server;

import javax.servlet.annotation.WebServlet;

import org.apache.log4j.Logger;
import org.cometmi.gwt.comet.client.TestAsyncService;
import org.cometmi.gwt.server.async.AsyncManager;
import org.cometmi.gwt.server.async.AsyncRemoteServiceServlet;

@SuppressWarnings("serial")
@WebServlet(name = "TestAsyncService", urlPatterns = { "/CometTest/test_async" }, asyncSupported = true)
public class TestAsyncServiceImpl extends AsyncRemoteServiceServlet implements TestAsyncService
{
	static protected Logger logger = Logger.getLogger(TestAsyncServiceImpl.class);

	public void asyncEcho(String echo, AsyncManager<String> asyncManager)
	{
		try
		{
			logger.debug("starting the function call");
			try
			{
				Thread.sleep(5000);
				logger.debug("attempting to complete the request");

				asyncManager.doCompleteForSuccess("server response: " + echo);
			}
			catch (InterruptedException e)
			{
				asyncManager.doCompleteForFailure(e);
			}
		}
		catch (Exception e1)
		{
			e1.printStackTrace();
		}
	}

	@Override
	public String asyncEcho(String echo)
	{
		return null;
	}
}
